-- @owner: @zhanghuan96
-- @date: 2024/12/10
-- @testpoint: GMS_UTILITY.COMPILE_SCHEMA函数，编译自定义函数，部分步骤合理报错
@conn PrimaryDbAmode;
--前置条件
drop extension if exists gms_utility;
create extension gms_utility;
--step1:创建视图;expect:成功
drop schema if exists s_compile0008 cascade;
create schema s_compile0008;
set current_schema to s_compile0008;
--step2:设置参数;expect:成功
set behavior_compat_options = 'plpgsql_dependency';
--step3:创建类型;expect:成功
drop type if exists type_compile0008 cascade;
CREATE TYPE type_compile0008 AS (
    field1 INTEGER,
    field2 INTEGER
);
--step4:创建函数;expect:成功
CREATE OR REPLACE FUNCTION func_compile0008(input_type type_compile0008)
RETURNS INTEGER AS $$
BEGIN
    RETURN input_type.field1 + input_type.field2;
END;
$$ LANGUAGE plpgsql;
/
--step5:调用函数;expect:成功
SELECT func_compile0008(ROW(10, 20)::type_compile0008) AS result;
--step6:查询系统表;expect:valid字段为t
select valid from pg_object where object_type='P' and object_oid in 
(select oid from pg_proc where propackageid = 0 and proname='func_compile0008' and 
pronamespace = (select oid from pg_namespace where nspname = 's_compile0008'));
--step7:类型增加字段;expect:成功
alter type type_compile0008 add attribute a int;
--step8:执行函数，参数2为false;expect:成功
call gms_utility.compile_schema('s_compile0008', false);
--step9:查询系统表;expect:valid字段为t
select valid from pg_object where object_type='P' and object_oid in
(select oid from pg_proc where propackageid = 0 and proname='func_compile0008'
and pronamespace = (select oid from pg_namespace where nspname = 's_compile0008'));
--step10:执行全编译;expect:成功
 call gms_utility.compile_schema('s_compile0008', true);
--step11:清理环境;expect:成功
drop schema s_compile0008 cascade;
drop extension if exists gms_utility;
reset current_schema;
reset behavior_compat_options;
